<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
	"http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>Test DateTextBox Widget</title>

		<style type="text/css">
			@import "../../../dojo/resources/dojo.css";
			@import "../css/dijitTests.css";

			.testExample {
				background-color:#fbfbfb;
				padding:1em;
				margin-bottom:1em;
				border:1px solid #bfbfbf;
			}

			.noticeMessage {
				color:#093669;
				font-size:0.95em;
				margin-left:0.5em;
			}

			.dojoTitlePaneLabel label {
				font-weight:bold;
			}
		</style>

		<!-- required: the default dijit theme: -->
		<link id="themeStyles" rel="stylesheet" href="../../../dijit/themes/tundra/tundra.css">

		<!-- required: dojo.js -->
		<script type="text/javascript" src="../../../dojo/dojo.js"
			djConfig="isDebug: true, parseOnLoad: true, extraLocale: ['de-de', 'en-us']"></script>

		<!-- only needed for alternate theme testing: -->
		<script type="text/javascript" src="../_testCommon.js"></script>

		<script type="text/javascript">
			dojo.require("dijit.dijit"); // optimize: load dijit layer
			dojo.require("dijit.form.DateTextBox");
			dojo.require("dijit.form.Form");
			dojo.require("dojo.date.locale");
			dojo.require("dojo.parser");	// scan page for widgets and instantiate them

			function eventHandler(e){
				// use this.domNode.getAttribute('widgetId') to show "this" is the widget
				// mouseleave/enter map to mouseout/over in all browsers except IE
				console.log(this.domNode.getAttribute('widgetId') + ' ' + arguments[0].type);
			}
		</script>
	</head>

	<body class="tundra">

		<h1 class="testTitle">Test DateTextBox Widget</h1>
		<!--	to test form submission, you'll need to create an action handler similar to
			http://www.utexas.edu/teamweb/cgi-bin/generic.cgi -->
		<form id="form1" dojoType='dijit.form.Form' action="" name="example" method="" onSubmit="return this.validate()">
			<div class="dojoTitlePaneLabel">
				<label for="local"> Date (local format) </label>
				<span class="noticeMessage">DateTextBox class, no attributes</span>
			</div>
			<div class="testExample">
				<input id="local" name="noDOMvalue" value="2008-12-31" type="text" dojoType="dijit.form.DateTextBox"
					onMouseEnter="eventHandler"
					onMouseLeave="eventHandler"
					onKeyDown="eventHandler"
					onChange="dojo.byId('oc1').value=''+arguments[0]"
				>
				onChange:<input id="oc1" size="34" disabled value="not fired yet!" autocomplete="off">
				<nobr>
				<button type="button" onclick="dijit.byId('local').attr('value', null);">attr('value',null)</button>
				<button type="button" onclick="dojo.byId('gv1').value=''+dijit.byId('local').attr('value');">attr('value')</button>
				<button type="button" onclick="dojo.byId('gv1').value=''+dijit.byId('local').value;">.value</button>
				<input id="gv1" size="34" disabled value="not called yet!" autocomplete="off">
				</nobr>
			</div>
			<div class="dojoTitlePaneLabel">
				<label for="localLong"> Date (local format - long) </label>
				<span class="noticeMessage">DateTextBox class,
					Attributes: required="true", trim="true", constraints={min:'2004-01-01',max:'2006-12-31',formatLength:'long'}. Works for leap years</span>
			</div>
			<div class="testExample">
				<div id="localLong" type="text" name="date1" value="2005-12-30"
					dojoType="dijit.form.DateTextBox"
					constraints="{min:'2004-01-01',max:'2006-12-31',formatLength:'long'}"
					required="true"
					trim="true"
					onChange="dojo.byId('oc2').value=arguments[0]"
					invalidMessage="Invalid date." >
					<script type="dojo/connect" event="onMouseEnter">eventHandler.apply(this, arguments)</script>
					<script type="dojo/connect" event="onMouseLeave">eventHandler.apply(this, arguments)</script>
					<script type="dojo/connect" event="onKeyDown">eventHandler.apply(this, arguments)</script>
				</div>
 				onChange:<input id="oc2" size="34" disabled value="not fired yet!" autocomplete="off">
				<input type="button" value="Destroy" onClick="dijit.byId('localLong').destroy(); return false;">
				<input type="button" value="set max to 2007-12-31" onClick="dijit.byId('localLong').constraints.max = new Date(2007,11,31); dijit.byId('localLong').validate(false); return false;">
			</div>
			<div class="dojoTitlePaneLabel">
				<label for="american"> Date (American format) </label>
				<span class="noticeMessage">DateTextBox class,
					Attributes: lang="en-us", required="true", constraints={min:'2004-01-01',max:'2006-12-31'}. Works for leap years.
					Prompt message whenever field is blank.
				</span>
			</div>
			<div class="testExample">
				<div id="american" type="text" name="date2" value="2005-12-30"
					dojoType="dijit.form.DateTextBox"
					constraints="{min:'2004-01-01',max:'2006-12-31'}"
					lang="en-us"
					required="true"
					promptMessage="mm/dd/yyyy"
					invalidMessage="Invalid date. Use mm/dd/yyyy format.">
					<script type="dojo/method" event="onMouseEnter">eventHandler.call(this, arguments[0])</script>
					<script type="dojo/method" event="onMouseLeave">eventHandler.call(this, arguments[0])</script>
					<script type="dojo/method" event="onKeyDown">eventHandler.call(this, arguments[0])</script>
				</div>
			</div>
			<div class="dojoTitlePaneLabel">
				<label for="german"> Date (German format)</label>
				<span class="noticeMessage">DateTextBox class,
					Attributes: lang="de-de", constraints={min:2004-01-01, max:2006-12-31}. Works for leap years.
					Prompt message whenever field is blank.
				</span>
			</div>
			<div class="testExample">
				<input id="german"/>
			</div>

			<div class="dojoTitlePaneLabel">
				<label for="pattern"> Date, overriding pattern</label>
				<span class="noticeMessage">Date, overriding pattern with dd-MM-yyyy</span>
			</div>
			<div class="testExample">
				<input id="pattern" name="noDOMvalue" type="text" dojoType="dijit.form.DateTextBox" constraints="{datePattern:'dd-MM-yyyy', strict:true}">
			</div>
			<div class="dojoTitlePaneLabel">
				<strong>Using title attrib for label</strong>
				<span class="noticeMessage">DateTextBox class,
					Attributes: lang="en-us", required="true", prompt meessage, invalid message
					Prompt message whenever field is blank.
				</span>
			</div>
			<div class="testExample">
				<div id="american2" type="text" name="date20" value="2008-12-30"
					dojoType="dijit.form.DateTextBox"
					title="Date in month, day, year format"
					lang="en-us"
					required="true"
					promptMessage="mm/dd/yyyy"
					invalidMessage="Invalid date. Use mm/dd/yyyy format.">
				</div>
			</div>

			<script>
			// See if we can make a widget in script and attach it to the DOM ourselves.
			dojo.addOnLoad(function(){
				dojo.connect(dijit.byId('pattern'), "onMouseEnter", eventHandler);
				dojo.connect(dijit.byId('pattern'), "onMouseLeave", eventHandler);
				dojo.connect(dijit.byId('pattern'), "onKeyDown", eventHandler);

				var props = {
					name: "date4",
					value: new Date(2006,10,29),
					constraints: {min:new Date(2004,0,1),max:new Date(2006,11,31)},
					lang: "de-de",
					onMouseEnter: eventHandler,
					onMouseLeave: eventHandler,
					onKeyDown: eventHandler,
					promptMessage: "dd.mm.yy",
					rangeMessage: "Enter a date in the year range 2004-2006.",
					invalidMessage: "Invalid date. Use dd.mm.yy format."
				};
				var w = new dijit.form.DateTextBox(props, "german");
			});
			</script>

			<script>
				function displayData() {
					var f = document.getElementById("form1");
					var s = "";
					for (var i = 0; i < f.elements.length; i++) {
						var elem = f.elements[i];
						if (elem.name == "button")  { continue; }
						s += elem.name + ": " + elem.value + "\n";
					}
					alert(s);
				}
			</script>

			<div class="dojoTitlePaneLabel">
				<label for="fromDate"> Date pairs, to/from</label>
			</div>
			<div class="testExample">
				From: <input id="fromDate" type="text" name="fromDate" dojoType="dijit.form.DateTextBox"
					required="true"
					onChange="dijit.byId('toDate').constraints.min = this.attr('value');" />
				To: <input id="toDate" type="text" name="toDate" dojoType="dijit.form.DateTextBox"
					required="true"
					onChange="dijit.byId('fromDate').constraints.max = this.attr('value');" />
			</div>

			<div>
				<button type="button" name="button" onclick="displayData(); return false;">view data</button>
				<input type="submit" name="submit" />
				<input type="reset" name="reset" />
			</div>
		</form>
	</body>
</html>
